package proyectos.cibertec.core.jpa;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

public class Main {


	private EntityManagerFactory emf;
	private EntityManager em;
	
	private void setup() {
		emf = Persistence.createEntityManagerFactory("SASC");
		em = emf.createEntityManager();
	}
	
	public static void main(String[] args) {
		Main m = new Main();
		m.setup();
		m.insert();
	}
	
	private void insert(){
		
		//las fechas son tipos timestamp
		
		Primarymember pm = new Primarymember();
		
		pm.setFirstname("");
		pm.setBirthdate(null);
		pm.setLastname("");
		pm.setGender((short) 0);
		
		Membership ms = new Membership();
		
		ms.setLastrenewaldate(null);
		ms.setMembershipType((short) 0);
		ms.setMembersince(null);
		ms.setPrimarymember(pm);
		pm.setMembership(ms);
		
		Address ad = new Address();
		
		ad.setAptno(null);
		ad.setCity("Lima");
		ad.setCountry("Peru");
		ad.setState("Lima");
		ad.setStreetname("Av. las churumbelas");
		ad.setStreetno("630");
		ad.setZipcode("051");
		ad.setPrimarymember(pm);
		
		pm.setAddress(ad);
		
		Contactinfo ci = new Contactinfo();
		
		ci.setCellno("985636338");
		ci.setHomeno("4614909");
		ci.setWorkno("2198000");
		ci.setEmail("xxxx@hotmail.com");
		ci.setPrimarymember(pm);
		
		pm.setContactinfo(ci);
		
		
		
		em.getTransaction().begin();
		//Operadoras
		em.persist(pm);
		
		
		em.getTransaction().commit();
		em.flush();
		
	}
	
	public Main() {
		//insert();
	}

	
	
}
